package com.longteng.testng;

import com.longteng.testng.binder.Binder;
import com.longteng.testng.param.IGenerator;
import com.longteng.testng.param.ProxyGenerator;
import org.testng.annotations.DataProvider;

import java.lang.reflect.Method;
import java.util.Iterator;

/**
 * Created by sky on 15-12-23
 */
public abstract class BenchMark  {

    private Config config;

    public BenchMark(){
        this.config = new Config();
        init(config);
    }

    public abstract void init(Config config);


    @DataProvider
    public Iterator<Object[]> proxy(Method testMethod) throws Exception {
        if(config.getGenerator() == null){
            throw new Exception("未指定文件加载类,请指定generator");
        }
        return new BenchMarkIterator(config,testMethod);
    }


    public static class Config{

        public Config(){
            this.binder = new Binder();
            this.generator = ProxyGenerator.getInstance();
        }

        private Binder binder;

        private IGenerator generator;

        public Binder getBinder() {
            return binder;
        }

        public void setBinder(Binder binder) {
            this.binder = binder;
        }

        public IGenerator getGenerator() {
            return generator;
        }

        public void setGenerator(IGenerator generator) {
            this.generator = generator;
        }
    }
}
